package com.luguokong.pet_rescue.controller;

import com.luguokong.pet_rescue.pojo.Adopt;
import com.luguokong.pet_rescue.service.AdoptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/adopt")
public class AdoptCtrl {
    @Autowired
    private AdoptService adoptService;

    @GetMapping("/getByPage")
    public List<Adopt> selectAdoptAllByPageNumByPageSize(int pageNum, int pageSize){
        List<Adopt> adoptList = adoptService.selectAdoptAllByPageNumByPageSize((pageNum-1)*pageSize, pageSize);
        return adoptList;
    }

    @GetMapping("/getDataCount")
    public int selectDataCount(){
        int i = adoptService.selectDataCount();
        return i;
    }

    @PostMapping("/insertAdopt")
    public int insertAdopt(@RequestBody Adopt adopt){
        int i = adoptService.insertAdopt(adopt);
        return i;
    }

    @GetMapping("/deleteAdoptById")
    public int deleteAdoptById(int adoptId){
        int i = adoptService.deleteAdoptById(adoptId);
        return i;
    }

    @PostMapping("/updateAdoptById")
    public int updateAdoptById(@RequestBody Adopt adopt){
        int i = adoptService.updateAdoptById(adopt);
        return i;
    }

    //    查询每个宠物类型的领养数量
    @GetMapping("/selectGroupByPetType")
    public List<Map<String, Number>> selectGroupByPetType(){
        List<Map<String, Number>> mapList = adoptService.selectGroupByPetType();
        return mapList;
    }

}
